#include "cpu/exec/helper.h"

make_helper(lods_b){
    current_sreg = R_DS;
    reg_b(R_AL) = swaddr_read(reg_l(R_ESI),1);
    int32_t incdec;
    if(cpu.eflags.DF == 0){
        incdec = 1;
    }
    else{
        incdec = -1;
    }
    reg_l(R_ESI) += incdec;
    print_asm("lodsb");
    return 1;
}

make_helper(lods_w){
    current_sreg = R_DS;
    reg_w(R_AX) = swaddr_read(reg_l(R_ESI),2);
    int32_t incdec;
    if(cpu.eflags.DF == 0){
        incdec = 2;
    }
    else{
        incdec = -2;
    }
    reg_l(R_ESI) += incdec;
    print_asm("lodsw");
    return 1;
}

make_helper(lods_l){
    current_sreg = R_DS;
    reg_l(R_EAX) = swaddr_read(reg_l(R_ESI),4);
    int32_t incdec;
    if(cpu.eflags.DF == 0){
        incdec = 4;
    }
    else{
        incdec = -4;
    }
    reg_l(R_ESI) += incdec;
    print_asm("lodsl");
    return 1;
}

make_helper_v(lods)